package com.ruoyi.config.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.config.domain.PayConfig;
import com.ruoyi.config.service.IPayConfigService;
import com.ruoyi.config.vo.UpdatePayConfigVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 支付方式配置Controller
 *
 * @author ruoyi
 * @date 2025-04-16
 */
@RestController
@RequestMapping("/payConfig/payConfig")
public class PayConfigController extends BaseController {
    @Autowired
    private IPayConfigService payConfigService;

    /**
     * 查询支付方式配置列表
     */
    @PreAuthorize("@ss.hasPermi('payConfig:payConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(PayConfig payConfig) {
        startPage();
        List<PayConfig> list = payConfigService.selectPayConfigList(payConfig);
        return getDataTable(list);
    }

    /**
     * 导出支付方式配置列表
     */
    @PreAuthorize("@ss.hasPermi('payConfig:payConfig:export')")
    @Log(title = "支付方式配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PayConfig payConfig) {
        List<PayConfig> list = payConfigService.selectPayConfigList(payConfig);
        ExcelUtil<PayConfig> util = new ExcelUtil<PayConfig>(PayConfig.class);
        util.exportExcel(response, list, "支付方式配置数据");
    }

    /**
     * 获取支付方式配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('payConfig:payConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(payConfigService.selectPayConfigById(id));
    }

    /**
     * 新增支付方式配置
     */
    @PreAuthorize("@ss.hasPermi('payConfig:payConfig:add')")
    @Log(title = "支付方式配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PayConfig payConfig) {
        return toAjax(payConfigService.insertPayConfig(payConfig));
    }

    /**
     * 修改支付方式配置
     */
    @PreAuthorize("@ss.hasPermi('payConfig:payConfig:edit')")
    @Log(title = "支付方式配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PayConfig payConfig) {
        return toAjax(payConfigService.updatePayConfig(payConfig));
    }

    /**
     * 删除支付方式配置
     */
    @PreAuthorize("@ss.hasPermi('payConfig:payConfig:remove')")
    @Log(title = "支付方式配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(payConfigService.deletePayConfigByIds(ids));
    }

    /**
     * 修改支付配置
     */
    @PreAuthorize("@ss.hasPermi('payConfig:payConfig:add')")
    @Log(title = "支付方式配置", businessType = BusinessType.INSERT)
    @PostMapping("updateAllPayConfig")
    public AjaxResult updateAllPayConfig(@RequestBody List<UpdatePayConfigVo> payConfig) {
        return toAjax(payConfigService.updateAllPayConfig(payConfig));
    }
}
